﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace UI
{
    public partial class cntParagraph : UserControl
    {
        #region cntParagraph : Members & Consts

            /// <summary>
            /// 
            /// </summary>
            private GUIParagraph paragraph = null;
            /// <summary>
            /// 
            /// </summary>
            private int parentParagraphID;

        #endregion

        #region cntParagraph : Initialization

            /// <summary>
            /// 
            /// </summary>
            /// <param name="id"></param>
            /// <param name="parentID"></param>
            public cntParagraph(int id, int parentID)
            {
                InitializeComponent();
                paragraph = new GUIParagraph("", id, 0.00000);
                this.parentParagraphID = parentID;
            }
            
            /// <summary>
            /// 
            /// </summary>
            /// <param name="paragraph"></param>
            /// <param name="parentID"></param>
            internal cntParagraph(GUIParagraph paragraph, int parentID)
            {
                InitializeComponent();
                this.paragraph = paragraph;
                this.parentParagraphID = parentID;
            }

        #endregion

        #region cntParagraph : Enums
            
            /// <summary>
            /// 
            /// </summary>
            public enum CntParagraphActions
            {
                Add_Paragraph = 0,
                Add_Header = 1,
                Remove_Paragraph = 2,
                Remove_Header = 3
            };
            
        #endregion

        #region cntParagraph : Properties

            /// <summary>
            /// 
            /// </summary>
            internal GUIParagraph ControlParagraph
            {
                get
                {
                    if (this.paragraph != null)
                    {
                        this.paragraph.GUIDocumentItemText = richTextBody.Text;
                        this.paragraph.GUIDocumentItemWeight = Double.Parse(numudWeight.Value.ToString());
                        return paragraph;
                    }
                    return null;
                }
            }

            /// <summary>
            /// 
            /// </summary>
            internal bool RemoveMe
            {
                get
                {
                    return chckRemove.Checked;
                }
            }

            /// <summary>
            /// 
            /// </summary>
            internal int ParentID
            {
                get
                {
                    return this.parentParagraphID;
                }
            }

        #endregion

        #region cntParagraph : Delegates

            /// <summary>
            /// 
            /// </summary>
            /// <param name="action"></param>
            /// <param name="parameters"></param>
            /// <returns></returns>
            public delegate Object[] CntParagraphEventHandler(CntParagraphActions action, Object[] parameters);

        #endregion

        #region cntParagraph : Events

            /// <summary>
            /// 
            /// </summary>
            public event CntParagraphEventHandler CntParagraphEvent;

        #endregion

        #region cntParagraph : EventHandlers

            /// <summary>
            /// 
            /// </summary>
            /// <param name="action"></param>
            /// <param name="parameters"></param>
            /// <returns></returns>
            protected virtual Object[] OnMakingAction(CntParagraphActions action, Object[] parameters)
            {
                if (CntParagraphEvent != null)
                    return CntParagraphEvent(action, parameters);
                return null;
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void cntParagraph_Load(object sender, EventArgs e)
            {
                if (paragraph != null)
                {
                    lblID.Text = paragraph.GUIParagraphID.ToString();
                    richTextBody.Text = paragraph.GUIDocumentItemText;
                    numudWeight.Value = decimal.Parse(paragraph.GUIDocumentItemWeight.ToString());
                }
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnAddHeader_Click(object sender, EventArgs e)
            {
                OnMakingAction(CntParagraphActions.Add_Header, new Object[] {this.Left,this.paragraph.GUIParagraphID });
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnAddParagraph_Click(object sender, EventArgs e)
            {
                OnMakingAction(CntParagraphActions.Add_Paragraph, new Object[] {this.Left, this.paragraph.GUIParagraphID});
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void cntParagraph_Resize(object sender, EventArgs e)
            {
                richTextBody.Width = this.Width - 70;
                btnAddParagraph.Left = this.Width - btnAddParagraph.Width - 15;
                numudWeight.Left = this.Width - numudWeight.Width - 15;
                btnAddHeader.Left = btnAddParagraph.Left - btnAddHeader.Width - 15;
                lblParagraphWeight.Left = numudWeight.Left - lblParagraphWeight.Width - 15;
            }
        #endregion

        #region cntParagraph : Methods

        #endregion
    }
}
